package cn.yangliu.springbatch.job;

import cn.yangliu.springbatch.entity.Role;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.annotation.BeforeStep;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;

/**
 * the type of springbatch
 *
 * <p>
 * .
 *
 * @author 杨柳
 * @date 2021-07-12
 */
@Component
public class RoleProcessor implements ItemProcessor<Role, Role> {

    /**
     * 日志记录操作对象 slf4j门面框架
     * 定义为常量
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(RoleProcessor.class);

    @Override
    public Role process(Role role) throws Exception {

        //模拟  假装处理数据,这里处理就是打印一下
        LOGGER.info("processor data : " + role.toString());
        return role;
    }


    @BeforeStep
    public void beforeStep(StepExecution stepExecution) {
        Object user = stepExecution.getExecutionContext().get("user");
        LOGGER.info("step context中的数据: {}", user);
        Object userList = stepExecution.getJobExecution().getExecutionContext().get("userList");
        System.out.println("role processor : " + userList);
    }
}
